/*
 *  tf_listmodel.h
 *  Perceel
 *
 *  Created by Nicola Gigante on 17/03/08.
 *  Copyright 2008 Nicola Gigante. All rights reserved.
 *
 */

#ifndef __TF_LISTMODEL_H__
#define __TF_LISTMODEL_H__

#include <QAbstractListModel>
#include <QList>
#include <QVariant>
#include <QMessageBox>
#include <QFile>

#include "tf.h"
#include "tfwriter.h"
#include "tfreader.h"

class TFListManager : public QAbstractListModel
{
	Q_OBJECT
	
	QList<TF> functions;
	
	bool m_modified;
	QString m_filename;
	
public:
	TFListManager(QObject *parent = 0) : QAbstractListModel(parent),
										 m_modified(false) {}
	
	void addFunction(TF tf);
	void delFunction(int f);
	
	// File management methods
	bool modified() const { return m_modified; }
	bool isNew() const { return m_filename.isNull(); }
	QString filename() const { return m_filename; }
	void setFilename(QString f) { m_filename = f; } 
	bool save();
	bool open(QString filename);
	
	// Model methods
	int rowCount(const QModelIndex & = QModelIndex()) const { return functions.count(); }
	QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const;
signals:
	void modified(bool m);
	
private:
	void setModified(bool m) { m_modified = m; emit modified(m); }
};

#endif
